package com.baidumap.administrator.happystudy.ui;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;

import com.ab.http.OnMessageResponse;
import com.ab.view.sliding.AbSlidingTabView;
import com.baidumap.administrator.happystudy.fragment.Fragment_OrderList;
import com.baidumap.administrator.happystudy.fragment.Fragment_OrderList_YiFuKuan;
import com.baidumap.administrator.happystudy.R;
import com.baidumap.administrator.happystudy.base.AppBaseActivity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * 描述：订单
 * 作者：xiaoxing on 17/4/10 22:41
 * 邮箱：2235445233@qq.com
 */
public class OrderActivity extends AppBaseActivity implements OnMessageResponse {

    @Bind(R.id.mAbSlidingTabView)
    AbSlidingTabView mAbSlidingTabView;

    @Override
    public int bindLayout() {
        return R.layout.activity_order;
    }

    @Override
    public void initView(View view) {
        super.initView(view);
        initTopTab(view);
    }

    @Override
    public void doBusiness(Context mContext) {
        super.doBusiness(mContext);
        setHeaderBack();
        setHeaderTitle(R.string.order);

    }

    /**
     * 设置当前item
     */
    private void setCurrentItem() {
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            int item = bundle.getInt("item");
            mAbSlidingTabView.getViewPager().setCurrentItem(item);
        }

    }

    /**
     * 初始化顶部的tab
     */
    private void initTopTab(View view) {
        //mAbSlidingTabView = (AbSlidingTabView) view.findViewById(R.id.mAbSlidingTabView);
        //缓存数量
        mAbSlidingTabView.getViewPager().setOffscreenPageLimit(5);


        Fragment_OrderList_YiFuKuan page1 = new Fragment_OrderList_YiFuKuan();
        Fragment_OrderList page2 = new Fragment_OrderList();

        List<Fragment> mFragments = new ArrayList<Fragment>();
        mFragments.add(page1);
        mFragments.add(page2);

        List<String> tabTexts = new ArrayList<String>();
        tabTexts.add(getString(R.string.yi_fu_kuan));
        tabTexts.add(getString(R.string.dai_fu_kuan));
//        tabTexts.add(getString(R.string.dai_tui_kuan));

        //设置样式
        mAbSlidingTabView.setTabTextColor(Color.BLACK);
        mAbSlidingTabView.setTabSelectColor(Color.rgb(185, 21, 29));
        mAbSlidingTabView.setTabBackgroundResource(R.drawable.tab_bg);
        mAbSlidingTabView.setTabLayoutBackgroundResource(R.mipmap.slide_top);
        //演示增加一组
        mAbSlidingTabView.addItemViews(tabTexts, mFragments);

        mAbSlidingTabView.setTabPadding(20, 8, 20, 8);
        setCurrentItem();
    }


    @Override
    public void onMessageResponse(String url, JSONObject jo) throws JSONException {

    }

    @Override
    public void onMessageResponse(String url, JSONArray jo) throws JSONException {

    }

    @Override
    public void onMessageResponse(String url, String str) throws Exception {

    }
}
